	@include('admin.head')
	<div class="container">
		<div class="row">
			@include('admin.side')
			<div class="col-md-10" id="content-wrapper" style="position:relative;">
				<div class="row">
					<style>
					#cover{
						width: 100%;
						height: 100%;
						position: absolute;
						top: 0;
						background: rgba(0,0,0,0.5);
						z-index: 1000;
						display: none;
					}
					</style>
					<div id="cover">
						<div class="row">
							<div class="col-xs-10">
							<div class="col-xs-6 col-xs-offset-4">
								<div class="main-box">
									<h2>管理员账号注册</h2>
									<div class="row" >
										<div class="form-group">
											<label for="username">用户名</label>
											<input type="email" class="form-control" id="username" placeholder="用户名" name="people">
										</div>
										<div class="form-group">
											<label for="pass">密码</label>
											<input type="password" class="form-control" id="pass" placeholder="密码">
										</div>
										<div class="form-group">
											<label for="pass">确认密码</label>
											<input type="password" class="form-control" id="passed" placeholder="确认密码">
										</div>
										<div style="margin-top:50px;"></div>
										<button type="button" class="btn btn-info" id="btn_sub"> 添 加 </button>
										<button type="button" class="btn btn-danger" id="btn_cancel"> 取 消 </button>
									</div>
								</div>

							</div>
						</div>
						</div>
					</div>

				<div class="col-xs-12">
					<div class="main-box clearfix">
						<div class="clearfix">
							<h2 class="pull-left">管理员</h2>
							<div class="filter-block pull-right">
								<button id="btn_add" class="btn btn-primary pull-right">
									<i class="fa fa-plus-circle fa-lg"></i> 添加管理员
								</button>

							</div>
						</div>
						<div class="table-responsive">
							<table class="table user-list" id="all-admins">
								<thead>
									<tr>
										<th data-column-id="id">
											<span>ID</span>
										</th>
										<th data-column-id="account" data-sortable="false">
											<span>用户名</span>
										</th>
										<th data-column-id="last_login" data-sortable="false">
											<span>最后登录时间</span>
										</th>
										<th data-column-id="last_login_ip" data-sortable="false">
											<span>最后登录IP</span>
										</th>
										<th data-sortable="false" data-formatter="commands">
											<span>操作</span>
										</th>
									</tr>
								</thead>
								<tbody>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
	@include("admin.footer")
	@include("admin.common")
</body>

<script type="text/javascript">
var tempAid = 0;
var labelsSetting = {
	infos: "当前第 {{ctx.start}} 条 到 {{ctx.end}} 条 共 {{ctx.total}} 条数据",
	search: "搜索",
	loading: "正在加载...",
	noResults: "未找到您要的数据...",
	refresh: "刷新",
	all: "全部"
};
$("#all-admins").bootgrid({
	rowCount: [10, 25, 50],
    ajax:true,
    url: "admins/list",
    labels:labelsSetting,
    formatters: {
    	"commands": function(column, row){
    		return '<a href="javascript:void(0);" aid="' + row.id + '" class="table-link doEdit"><span class="fa-stack"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-pencil fa-stack-1x fa-inverse"></i></span></a>' + '<a href="javascript:void(0);" aid="' + row.id + '" class="table-link doDelete"><span class="fa-stack"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-trash-o fa-stack-1x fa-inverse"></i></span></a>';
    	}
    }
}).on("loaded.rs.jquery.bootgrid", function (e)
    {

    	$(".doEdit").bind('click',function(){
    		var aid = $(this).attr('aid');
    		tempAid = aid;
    		$('#cover').show();
    		$('#cover').find('#btn_sub').text("提交")
    		$.get("admins/get_admin?aid="+aid,function (data){
    			$("input[name='people']").val(data.data[0].account);
    		})
    	})

    	$(".doDelete").bind('click',function(){
    		var aid = $(this).attr('aid');
    		confirm("", "确定要删除吗?", "warning", function(data){
    			if(data == 1){
    				$.post("admins/delete_admin", {aid: aid}, function (data){
    					if(data.success){
    						success("", "删除成功");
    						setTimeout(function(){
    							window.location.reload();
    						}, 1000)
    					}
    				})
    			}
    		})
    	});

    });



$("#all-admins-header").hide();

$('#btn_add').bind('click',function(){
	$('#cover').show();
	$('#cover').find('#btn_sub').text("添加")
})
$('#btn_cancel').bind('click',function(){
	$("#username").val('');
	$("#pass").val('');
	$("#passed").val('');
	$('#cover').hide();
	tempAid = 0;
})

$("#btn_sub").click(function(){
	var account = $("#username").val().trim();
	var password = $("#pass").val().trim();
	var passworded = $("#passed").val().trim();
	if(account == ''){
		warning('','请输入6-12位用户名');
		return;
	}
	if(password == ''){
		warning('','请输入密码');
		return;
	}
	if(password != passworded){
		warning('','两次密码不一致');
		return;
	}
	if( tempAid != 0 )
	{
		$.post("admins/update_admin", {
			aid : tempAid,
			password : encrypt(password),
		}, function(data){
			if(data.success){
				success('','提交成功')
				setTimeout(function(){
					window.location.reload();
				}, 1000)
			}else{
				warning("" ,data.msg);
			}
		})
		return;
	}
	$.post("admins/add_admin_user", {
		account : account,
		password : encrypt(password),
	}, function(data){
		if(data.success){
			success('','提交成功')
			setTimeout(function(){
				window.location.reload();
			}, 1000)
		}else{
			warning("" ,data.msg);
		}
	})
})





</script>


</html>